
const baseUrl = 'https://www.xxx.xxx:8089/mqtt/';

const request = function(options) {
	uni.onNetworkStatusChange(function(res) {
		if (!res.isConnected) {
			uni.showToast({
				title: '网络连接不可用！',
				icon: 'none'
			});
		}
		return false
	});
    options.url = baseUrl + options.url
    try {
        const token = uni.getStorageSync('token');
        if (token != null) {
            options.header = {
                'token': token || null
            };
        }else{
			return
		}
    } catch (err) {
        console.log(err)
    }
	let res = uni.request(options)
    return res;
}

const hadToken = () => {
	let token = uni.getStorageSync('token');

	if (token == '' || token == undefined || token == null) {
		uni.showToast({
			title: '账号已过期，请重新登录',
			icon: 'none',
			complete: function() {
				uni.reLaunch({
					url: '/pages/login/index'
				});
			}
		});
		return false;
	}
	return true
}
export default {
	baseUrl,
	request,
	hadToken
}
